local skel = fk.CreateSkill{--定义
  name = "kt_st__jinji",
}

local KleeU = require "packages/klee_xy_I/utility/k_utility"

Fk:loadTranslationTable{
  ["kt_st__jinji"] = "近急",
  [":kt_st__jinji"] = "有角色死亡后，你可以变更势力。你每满足一项，你的手牌上限和摸牌阶段摸牌数便+1：为大势力；你为大势力角色包围；与主公同势力；主公有主公技。",

  ["$kt_st__jinji1"] = "逢源左右，招徕远近，是朋却非友。",
  ["$kt_st__jinji2"] = "多事之秋，节度皆以从权养志，而号称帅。",

}

skel:addEffect(fk.Deathed, {--变势力
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_use = function (self, event, target, player, data)
    KleeU.asktoChangeKingdom(player,skel.name)
  end,
})

---@param player Player
---@return integer
local function getload(player)
  local ii = 0
  --大势力
  if KleeU.isBigKingdomPlayer(player) then
    ii = ii+1
  end
  --为大势力角色包围
  if player:getNextAlive() ~= player:getLastAlive() and player:getNextAlive().kingdom == player:getLastAlive().kingdom and KleeU.isBigKingdomPlayer(player:getNextAlive()) then
    ii = ii+1
  end
    local loadp = player
  if loadp.role ~= "lord" then
    loadp = player.next
    while loadp.role ~= "lord" and loadp ~= player do
      loadp = loadp.next
    end
  end
  if loadp.role == "lord"then
    --与主公同势力
    if loadp.kingdom == player.kingdom then
      ii = ii+1
    end
    --主公有主公技
    for _,s in ipairs(loadp.player_skills) do
      if s:hasTag(Skill.Lord) then
        ii = ii+1
        break
      end
    end
    --
  end
  return ii
end

skel:addEffect(fk.DrawNCards, {
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.n = data.n + getload(player)
  end,
})

skel:addEffect("maxcards", {--加上限
  correct_func = function(self, player)
    if player:hasSkill(skel.name) then
      return getload(player)
    end
  end,
})



return skel